<template>
	<view class="content">
		<view class="select" v-if="!userAddress.userName">
			<view class="select_one" @tap="getUserAddress">
				选择地址
			</view>
			<button style="width: 200rpx;" open-type="openSetting">授权</button>
		</view>
		<view class="select" v-else>
			<view class="">
				<view class="">
					{{userAddress.userName}}  {{userAddress.telNumber}}
				</view>
				<view class="">
					{{ addressDetail }}
				</view>
			</view>
		</view>
		<view class="goods_bottom" @scrolltolower="scrolltolower"
			 v-for="(item,index) in title" :key="item.goods_id">
			<view class="bottom_commodity">
				<image :src=" item.goods_big_logo || '../../static/tads/empty.png' " mode=""></image>
				<view class="bottom_commodity_rigth">
					<navigator class="bottom_commodity_rigth_top" :url="'../goods_detail/index?goods_id='+item.goods_id " open-type="navigate">
						{{item.goods_name}}
					</navigator>
					<view class="bottom">
						<view class="price">
							{{item.goods_price}}
						</view> 
						<view class="unmber">
							<view class="unmber_">{{item.quantity}}</view>
						</view>
					</view>
				</view>
			</view>
			
		</view>
		<view class="sloce">
			<view class="total">
				<view class="huji">
					合计：
				</view>
				<view class="price">
					{{ total_price }}
				</view>
			</view>
			<view class="go_sloce">
				<navigator class="payment" url="" open-type="navigate">
					去支付({{ product }})
				</navigator>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: [],
				check: false,
				userAddress: {},
			}
		},
		onLoad() {
			
		},
		computed:{
			total_price() {
				let price = 0
				this.title.forEach(item=>{
					if(item.isSelect){
						price += item.goods_price * item.quantity
					}
				})
				return price
			},
			product() {
				let arr = 0
				this.title.forEach(v=>{
					if(v.isSelect == true) {
						arr++
					}
				})
				return arr
			},
			addressDetail(){
				// 提取出需要拼接的地址信息
				const { detailInfo, countyName, cityName, provinceName } = this.userAddress;
				// 拼接并返回
				return provinceName + cityName + countyName + detailInfo;
			}
		},
		methods: {
			getUserAddress() {
				uni.chooseAddress({
					success: (res) => {
						this.userAddress = res
					}
				})
			}
		},
		onShow() {
			const list = uni.getStorageSync('cartData')
			this.title = list.filter(item=>item.isSelect)
		}
	}
</script>

<style lang="less">
.content {
	height: 100vh;
	background: #f3f3f3;
	.select {
		width: 710rpx;
		height: 186rpx;
		margin: 0 auto;
		background: #FFFFFF;
		display: flex;
		align-items: center;
		justify-content: center;
		.select_one {
			width: 300rpx;
			height: 98rpx;
			border: solid 2rpx red;
			border-radius: 150rpx;
			display: flex;
			justify-content: center;
			align-items: center;
		}
	}
	.goods_bottom {
		background-color: #FFFFFF;
		margin: 20rpx;
		background: ;
		position: relative;
		.bottom_commodity {
			flex: 9;
			padding: 20rpx;
			display: flex;
			image {
				width: 190rpx;
				height: 190rpx;
				flex-shrink: 0;
			}
			.bottom_commodity_rigth {
				flex: 1;
				font-size: 24rpx;
				padding: 20rpx 20rpx 0;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				.bottom_commodity_rigth_top {
					font-size: 24rpx;
					overflow : hidden;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-line-clamp: 3;
					-webkit-box-orient: vertical;
				}
				.bottom {
					display: flex;
					justify-content: space-between;
					align-items: center;
					.price {
						color: red;
						&::before {
							content: "￥";
							padding-right: 10rpx;
						}
					}
					.unmber {
						display: flex;
						justify-content: space-between;
						align-items: center;
						font-size: 30rpx;
						margin-right: 20rpx;
						&::before {
							content: "×";
						}
					}
				}
			}
		}
	}
}

.sloce {
	position: fixed;
	bottom: 0;
	width: 750rpx;
	height: 84rpx;
	display: flex;
	font-size: 30rpx;
	padding: 0 30rpx;
	box-sizing: border-box;
	background-color: #FFFFFF;
	.total {
		flex: 1;
		display: flex;
		justify-content: space-evenly;
		align-items: center;
		box-sizing: border-box;
		.radio {
			display: flex;
			justify-content: center;
			align-items: center;
		}
		.huji {
			padding-left: 20rpx;
		}
		.price {
			color: red;
			&::before {
				content: "￥";
				font-size: 24rpx;
			}
		}
	}
	.go_sloce {
		flex: 1;
		display: flex;
		justify-content: flex-end;
		align-items: center;
		.payment {
			width: 150rpx;
			height: 52rpx;
			background: #ea4350;
			color: #FFFFFF;
			border-radius: 75rpx;
			text-align: center;
			line-height: 52rpx;
		}
	}
}
</style>
